﻿<!DOCTYPE html>
<!--日常评估模板管理列表-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <!-- 行内编辑 css-->
    <style>
        .tb-edit .el-input {
            display: none
        }

        .tb-edit .current-row .el-input {
            display: block
        }

            .tb-edit .current-row .el-input + span {
                display: none
            }

        .tb-edit .el-select {
            display: none
        }

        .tb-edit .current-row .el-select {
            display: block
        }

            .tb-edit .current-row .el-select + span {
                display: none
            }

        .xian {
            display: block;
            text-align: center;
        }

        .yin {
            display: none;
            text-align: center;
        }

        .lineMust {
            position: absolute;
            right: 15px;
            bottom: 6px;
            bottom: 3px\0 !important;
            /* 兼容ie */
        }
    </style>
    <!-- 行内编辑 css-->
</head>

<body>
    <div id="app" v-cloak class="popupW50">
        <el-form ref="form" :inline="true" label-position="right" :model="formInline" class="demo-form-inline"
                 style="margin-bottom: 15px;">

            <el-row>
                <el-col class="head-tool">

                    <div class="new_title fl"><strong><img src="/static/images/icon1.png" />日常评估模板列表</strong></div>
                    <span>
                        <!--<btn text="添加检查项目" imgsrc="/static/images/add.png" linetype="3" @click="add">
                    </btn>-->
                        <!-- <btn :text="col.btnAdd" linetype="3" @click="UserInput('tj')"></btn> -->
                        <!-- <btn-uploadfile-list url="xxxx" linetype="3"></btn-uploadfile-list>
                    <btn-export-list url="xxxx" :forminline="this.formInline" linetype="3">
                    </btn-export-list> -->
                        <!--<btn :text="col.btnDelete" linetype="4" @click="onDelete"></btn>-->
                    </span>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{DailyAssessmentType.Type+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="formInline.model.assessTypeId" slot="suffix"
                                           :placeholder="DailyAssessmentType.Type" @change="onSubmit">
                                    <!-- <el-option :label="Type[0].value" value=""></el-option> -->
                                    <el-option v-for="item in Type" :label="item.value" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-button type="primary" @click="add">添加检查项目</el-button>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
        </el-form>


        <!--表格开始-->
        <el-table ref="table" stripe @current-change="tableHandleCurrentChange" class="tb-edit"
                  :data="ListItem.tableData" :row-key="getRowKeys" border
                  @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%;">


            <!-- 行内编辑 html-->
            <el-table-column prop="checkProject" :label="DailyAssessmentType.CheckProject">
                <template scope="scope">
                    <el-input size="mini" v-model="scope.row.checkProject" placeholder="请输入内容" >
                    </el-input>
                    <span>{{scope.row.checkProject}}</span>
                    <span class="lineMust" v-if="scope.row.checkProject.length<=0">
                        <!-- 必填项添加 -->
                        <img src="/static/images/exclamation.png" alt="">
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="points" :label="DailyAssessmentType.Points">
                <template scope="scope">
                    <el-input size="mini" v-model="scope.row.points" placeholder="请输入内容" >
                    </el-input>
                    <span>{{scope.row.points}}</span>
                    <span class="lineMust" v-if="scope.row.points.length<=0">
                        <!-- 必填项添加 -->
                        <img src="/static/images/exclamation.png" alt="">
                    </span>
                </template>
            </el-table-column>

            <el-table-column width="90" prop="update" label="编辑">
                <template slot-scope="scope">
                    <span class="start xian">
                        <button type="button" class="elst-bt-xg"
                                @click=Edit('xg',scope.row.id,scope.$index)>
                            <i class="el-icon-edit"></i>
                        </button>
                    </span>
                    <span class="end yin">
                        <button type="button" class="elst-bt-xg " @click="Save(scope.$index, scope.row)">
                            <i class="el-icon-circle-check-outline"></i>
                            <!-- 保存 -->
                        </button>
                        <!--<button type="button" @click.native.prevent="deleteRow(scope.$index, Form.CarryingToolList)">-->
                        <button type="button" class="elst-bt-xg " @click="Back(scope.$index, scope.row)">
                            <i class="el-icon-circle-close-outline"></i>
                            <!-- 撤销 -->
                        </button>
                    </span>
                </template>
            </el-table-column>
            <el-table-column width="90" label="操作" align="center">
                <template slot-scope="scope">
                    <button type="button" class="elst-bt-xg"
                            @click="deleteRow(scope.row.id,scope.$index)">
                        <i class="el-icon-delete"></i>
                    </button>
                </template>
            </el-table-column>
            <el-table-column prop="id" width="1" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{scope.row.id}}</span>
                </template>
            </el-table-column>
        </el-table>
        <!--<el-row type="flex" justify="end">
        <el-pagination ref="page" @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="ListItem.currentPage" :page-sizes="ListItem.pagesizes" :page-size="ListItem.pagesize"
            :layout="ListItem.layout" :total="ListItem.total">
        </el-pagination>
    </el-row>-->
        <el-row type="flex" justify="end" style="padding-top:5px;">

            <el-button type="primary" @click="onSubmitForm2">{{col.btnSave}}</el-button>

        </el-row>
        <el-dialog title="日常评估考核类型管理" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%"
                   height="80%" top="10vh" fullscreen="true">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        //获取分页数据
        function GetPageData1(mythis, currentIndex, url) {
            var currObj = mythis;
            mythis.delId = [];
            if (mythis.formInline.model.assessTypeId == null || mythis.formInline.model.assessTypeId == "" || mythis.formInline.model.assessTypeId == undefined) {
                currObj.ListItem.tableData = [];
                currObj.ListItem.total = 0;
                
            } else {

                
                myAjax("post", mythis, url, { model: mythis.formInline.model, offset: 0, limit: 100 }, function (response) {
                    console.log(response);
                    if (response.data.pageData.length == 0) {
                        currObj.ListItem.tableData = [];
                        currObj.ListItem.total = 0;
                    } else {
                        currObj.ListItem.tableData = response.data.pageData;
                        currObj.ListItem.total = response.data.pageData.length;
                    }
                });
            }
        }
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    ListItem: ListItem,
                    Type: [],
                    Form: {
                        id: guidEmpty,
                        assessTypeId: '',
                        checkProject: '',
                        points: '',
                    },
                    formInline: {
                        model: {
                            assessTypeId: '',
                            points: '',
                            editorTime: '',
                            checkProject: '',
                        },
                        offset: 0,
                        limit: 10
                    },
                    checkProjectTemp: '',
                    pointsTemp: '',
                    delId: [],
                    tempId: guidEmpty
                }
            }, created: function () {
                var currApp = this;
                window.onresize = function () {
                    currApp.ListItem.tableHeight = window.innerHeight -
                        currApp.$refs.table.$el.offsetTop - 60;
                    if (currApp.ListItem.tableHeight < 112) {
                        currApp.ListItem.tableHeight = 112;
                    }
                }
            },
            mounted: function () {
                //获取下拉菜单内容
                this.getTypeList();
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);

                //getDicData('cbssglb');//getDicData('29');
                if (this.Type == null || this.Type == undefined) { } else {
                    if (this.Type.length > 0) { this.formInline.model.assessTypeId = this.Type[0].id; }
                    //this.formInline.model.Type = this.Type[0].value;
                }
            },

            created: function () {
                setTimeout(this.onSubmit, 100);

            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //初始化承包商类型
                getTypeList: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_DayCheckItem/CBSsglbGetList', { model: { category: 'cbssglb' }, offset: 0, limit: 100 }, function (response) {
                        mythis.Type = response.data;

                        //console.log(response.data.pageData);
                    }, false);
                },
                // 行内编辑 js
                add: function (formName) {
                    if ($('tbody tr').attr("class") == "el-table__row current-row") {
                        showMessage(msg.EditingNotCompleted, 'error');
                    } else {
                      
                        var newObj = {
                            checkProject: '',//添加是清空录入数据的，每一项都要有
                            points: ''
                        }

                        //this.Form.assessTypeId = this.formInline.model.assessTypeId;//添加是清空录入数据的，每一项都要有
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        this.ListItem.tableData.unshift(newObj);
                        setTimeout(function () {
                            $('.el-table__row:eq(0)').addClass('current-row');
                            $('.el-table__row:eq(0) span.end').removeClass('yin');
                            $('.el-table__row:eq(0) span.end').addClass('xian');
                            $('.el-table__row:eq(0) span.start').removeClass('xian');
                            $('.el-table__row:eq(0) span.start').addClass('yin');
                        }, 100);
                    }
                },
                //修改
                Edit: function (val, id, index) {
                    var tlist = this.ListItem.tableData;
                    this.checkProjectTemp = tlist[index].checkProject;
                    this.pointsTemp = tlist[index].points;
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row:eq(' + index + ')').addClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.end').removeClass('yin');
                    $('.el-table__row:eq(' + index + ') span.end').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').removeClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').addClass('yin');
                },
                // 保存
                Save: function (a, b) {
                    if (!b.checkProject || !b.points) {
                        showMessage(msg.NoMust, 'error');
                    } else {
                       
                        //this.onSubmitForm('form', b);

                        $('.el-table__row').removeClass('current-row');
                        console.log("a", a);
                        console.log("b", b);
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        //初始化数据
                        // this.GetPageData(1);
                        //setTimeout(this.GetPageData, 100);
                    }
                },
                Back: function (a, b) {
                    if (this.checkProjectTemp != "" || this.pointsTemp != "") {
                        b.checkProject = this.checkProjectTemp;
                        b.points = this.pointsTemp;
                        this.checkProjectTemp = "";
                        this.pointsTemp = "";
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                    } else {
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        this.ListItem.tableData.splice(a, 1);
                    }
                    
                   
                    ////初始化数据
                    //this.GetPageData(1);
                },
                deleteRow: function (id, delrow) {
                    var mythis = this;
                    //this.$confirm(' 是否确认继续?', '提示', {
                    //    confirmButtonText: '确定',
                    //    cancelButtonText: '取消',
                    //    type: 'warning'
                    //}).then(function () {
                    if (id == mythis.tempId || id == null || id == "") {
                        this.$confirm(' 是否确认继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            var list = mythis.ListItem.tableData;
                            list.splice(delrow, 1);
                        }).catch(function () {
                            showMessage("已取消删除!");
                        });
                    } else {
                        this.$confirm(' 是否确认继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            mythis.delId.push(id);
                            var list = mythis.ListItem.tableData;
                            list.splice(delrow, 1);
                        }).catch(function () {
                            showMessage("已取消删除!");
                        });
                    }


                    //}).catch(function () {
                    //    showMessage("已取消删除!");
                    //});
                },
                onSubmitForm: function (formName, obj) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        onSubmitForm(this, '/api/CBS_DayCheckItem/Save', obj);
                        //验证通过
                        // if (valid) {
                        //     onSubmitForm(this, '/api/DailyAssessmentType/Save', obj);
                        // } else {
                        //     //验证失败
                        //     return false;
                        // }
                    });
                },

                onSubmitForm2: function () {
                  
                        var mythis = this;
                        var sumS = 0;

                    for (var i = 0; i < mythis.ListItem.tableData.length; i++) {
                        sumS = parseFloat(sumS) + parseFloat(mythis.ListItem.tableData[i].points);
                        }
                    if (parseFloat(sumS) == 100) {

                        for (var i = 0; i < mythis.ListItem.tableData.length; i++) {
                            var saveModel = mythis.ListItem.tableData[i];
                            saveModel.assessTypeId = this.formInline.model.assessTypeId;
                            //onSubmitForm(this, '/api/CBS_DayCheckItem/Save', saveModel);
                            myAjax("post", mythis, '/api/CBS_DayCheckItem/Save', saveModel, function (response) {

                            }, false);
                        }
                        if (mythis.delId.length > 0) {
                            myAjax("post", mythis, '/api/CBS_DayCheckItem/DeleteMuti', mythis.delId, function (response) {
                                mythis.delId = [];
                            });
                        }
                        showMessage(msg.OperatingOk, 'success');

                    } else {
                        alert('权重分综合为100！');
                        return false;
                    }
                   
                },
                handblur: function () {
                    //this.$refs.table.setCurrentRow(999);
                    //console.log("c", 'c');
                },
                //table选中行handle
                tableHandleCurrentChange: function (currentRow) {
                    //this.currSeelctId = currentRow.id;
                    //this.currSeelctCell = currentRow;
                },
                // 行内编辑 js


                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },

                handleNodeClick: function (data) {
                    console.log(data);
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                //onDelete: function () { onDelete(this, '/api/CBS_DayCheckItem/DeleteMuti'); },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) { DialogShow(this, val, "DailyAssessmentTemplateManagementInput.html", id); },
                //获取分页数据
                GetPageData: function (currentIndex) { GetPageData1(this, currentIndex, '/api/CBS_DayCheckItem/GetList') },
                //查询方法
                onSubmit: function () {
                    this.GetPageData(1);//onSubmit(this); 
                },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                
            }
        });
    </script>
</body>

</html>